export enum CheckStatus {
    UNDO = 'UNDO',
    CORRECT = 'CORRECT',
    MISTAKE = 'MISTAKE'
}

export type Formula = {
    id: string
    first: number
    second: number
    sign: string
    signLabel: string
    status: CheckStatus
    answer?: number
}

export default class CCheck {
    task: Formula
    correct: number
    answer: number | undefined

    constructor (task: Formula, answer: number | undefined) {
        this.task = task
        this.correct = eval(`${task.first}${task.sign}${task.second}`)
        this.answer = answer
    }

    result (): Formula {
        let status: CheckStatus
        if (typeof this.answer === 'number') {
            status = this.answer === this.correct ?
                CheckStatus.CORRECT :
                CheckStatus.MISTAKE
        } else {
            status = CheckStatus.UNDO
        }

        return {
            ...this.task,
            answer: this.answer,
            status
        }
    }
}